package xyz.keyon.servlet;

import xyz.keyon.bean.Student;
import xyz.keyon.service.IStudentService;
import xyz.keyon.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "DeleteStudentServlet", urlPatterns = "/DeleteStudentServlet")
public class DeleteStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取响应头信息
        String sno = request.getParameter("sno");
        //调用业务逻辑层
        IStudentService service = new StudentServiceImpl();
        boolean result = service.deleteStudent(sno);
        //处理返回结果
        PrintWriter out = response.getWriter(); //响应对象
        if(result) {
            //增加成功
            request.setAttribute("result", "success");
        } else {
            //增加失败
            request.setAttribute("result", "failed");
        }
        //页面跳转（请求转发）
        request.getRequestDispatcher("QueryAllStudentsByPageServlet").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
